<?php
header('Content-type: text/vnd.wap.wml');
$mode		= $_REQUEST['mode'];
$noteid		= $_REQUEST['noteid'];
$title		= urldecode($_REQUEST['title']);
$content	= urldecode($_REQUEST['content']);
?>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE wml PUBLIC "-//PHONE.COM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<?php
	if($mode == 'edit'):  // this mode is obsolete since r13, but I retain here for future reuse??(maybe)
	// we receive a request to change a note:
	// print the following:
?>
<card title="Sửa ghi chú">
<onevent type="onenterforward">
	<refresh> 
		<setvar name="title" value=""/> 
		<setvar name="content" value=""/> 
	</refresh>
</onevent>  
<p>
	<b>Tiêu đề</b><br/>: 
	<input name="title" format="*M" emptyok="True" value="<?php echo $title ?>"/><br />
	<b>Nội dung</b>: 
	<input name="content" format="*M" emptyok="false" value="<?php echo $content ?>"/><br />
	<anchor>
	<go href="editnote.php" method="post">
		<postfield name="mode" value="post"/>
		<postfield name="noteid" value="<?php echo $noteid ?>"/>
		<postfield name="title" value="$(title)"/>
		<postfield name="content" value="$(content)"/>
	</go>
	Lưu
	</anchor>
<br/>
	&#169;2011 -  Vutrankien - vukien@hcm.fpt.vn<br/>  
</p>
</card>
<?php 
	elseif($mode == 'post'):
	// we have the data now we commit it to the database
?>
<card title="Kết quả:">
<p align="left">
<?php
		if ($db = new SQLite3('webnote.db3'))
		{
			$q = $db->exec("UPDATE notes SET title='".$db->escapeString($title)."', content='".$db->escapeString($content)."' WHERE noteid=$noteid");
			if($q === false)
				echo("<b>Couldn't update table:</b> ".$db->lastErrorMsg());
			else
			{
				echo "Insert successful\n";
?>
	<br/>
	<b>Tiêu đề</b>:  <?php echo $title ?><br />
	<b>Nội dung</b>: <?php echo $content ?><br />
	<a href="addnote.wml">Đăng ghi chú khác</a><br/>
	<a href="viewnote.php">Xem lại các ghi chú của bạn:</a><br/>
	&#169;2011 -  Vutrankien - vukien@hcm.fpt.vn<br/>  

<?php
			}
		}
		else
			echo("Couldn't open database!");
?>
</p>
</card>
<?php 
	endif;
?>
</wml>